from OptionsPage import OptionsPage
from Autotests.LocalMachine.UiObjectsMap.AirClient import Options
from Autotests.LocalMachine.Controls.ListView import WebListView
from Autotests.LocalMachine.Controls.LineEdit import WebLineEdit
from Autotests.LocalMachine.Controls.Button import WebButton


class FilterTab(OptionsPage):
    def __init__(self):
        super(FilterTab, self).__init__()
        self._textBoxFilterName = WebLineEdit(Options.Filter.tfFilterName)
        self._buttonAdd = WebButton(Options.Filter.btnAddFilter)
        self._buttonEdit = WebButton(Options.Filter.btnEditFilter)
        self._buttonDelete = WebButton(Options.Filter.btnDeleteFilter)
        self._listBoxFilters = WebListView(Options.Filter.listBoxFilters)

    def goToHomeLocation(self):
        super(FilterTab, self).goToHomeLocation()
        WebButton(Options.btnFilter).click()

    @OptionsPage.setter
    def addFilter(self, filterName = '.txt'):
         self._textBoxFilterName.typeText(filterName)
         self._buttonAdd.click()

    @OptionsPage.setter
    def deleteFilter(self, filterName):
        self._listBoxFilters.selectItemsByText(filterName)
        self._buttonDelete.click()

    @OptionsPage.setter
    def editFilter(self, oldFilterName, newFilterName = ".newFilterName"):
        self._listBoxFilters.selectItemsByText(oldFilterName)
        self._buttonEdit.click()
        self._textBoxFilterName.typeText(newFilterName)
        self._buttonAdd.click()

    @OptionsPage.getter
    def getFilterCount(self):
        return self._listBoxFilters.rowsCount()

    @OptionsPage.getter
    def isFilterInList(self, filterName):
        return self._listBoxFilters.hasItemsWithText(filterName)

